package com.niit.servlet;

import com.niit.pojo.StudentTable;
import com.niit.service.HbaseService;
import com.niit.service.impl.HbaseServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;

/**
 * @author Liu
 * @date 2022/2/9 8:57
 **/
@WebServlet("/updateServlet")
public class updateServlet extends HttpServlet {

    public void init(HttpServletRequest req, HttpServletResponse resp) throws UnsupportedEncodingException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String studentId = req.getParameter("studentId");
        String name = req.getParameter("name");
        String dateofenrollment = req.getParameter("dateofenrollment");
        String contactNumber = req.getParameter("contactNumber");
        String studentStatus = req.getParameter("studentStatus");
        StudentTable studentTable = new StudentTable(studentId, name, dateofenrollment, contactNumber, null, studentStatus);
        /**
         * 创建学生对象
         * **/
        HbaseService hbaseService = new HbaseServiceImpl();
        hbaseService.update(studentTable);
        /**
         * 进行更改操作
         * **/
        init(req, resp);
        PrintWriter pw = resp.getWriter();
        pw.write("<h1>当前用户" + studentId + "信息更改成功</h1>");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}
